package com.ego.dao.impl;

import com.ego.dao.UserInfoDao;
import com.ego.utils.JDBCUtils;
import com.ego.vo.UserInfoVo;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @author 袁梦达 2019012364
 */
public class UserInfoDaoImpl implements UserInfoDao {
    @Override
    public UserInfoVo getUserInfo(String userNumber){

        Connection connection = JDBCUtils.getConnection();
        PreparedStatement statement = null;
        try {
            String sql = "select * from user where number = ?";
            statement = connection.prepareStatement(sql);
            statement.setString(1, userNumber);
            ResultSet resultSet = statement.executeQuery();
            UserInfoVo userInfoVo = new UserInfoVo();
            if(resultSet.next()){
                userInfoVo.setUserNumber(resultSet.getString("number"));
                userInfoVo.setNickName(resultSet.getString("name"));
            }
            return userInfoVo;
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } finally {
            JDBCUtils.close(statement, connection);
        }
        return null;
    }
}
